package com.ohc.leetcode.数组;

/**
 * https://leetcode-cn.com/problems/max-consecutive-ones/
 */
public class 最大连续1的个数485 {

    public static int findMaxConsecutiveOnes(int[] nums) {
        int total = 0;
        int flag = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                flag = 0;
            }

            if (nums[i] == 1) {
                flag++;
                if (flag >= total) {
                    total = flag;
                }
            }


        }
        return total;
    }

    public static void main(String[] args) {
        int[] nums = {1, 0, 1, 1, 0, 1};
        int total = findMaxConsecutiveOnes(nums);
        System.out.println("total = " + total);
    }
}
